#include "BitTest.h"

void BitTest::get()
{
	ASSERT_EQUAL(true, Bit(true).get());
	ASSERT_EQUAL(false, Bit(false).get());
	ASSERT_EQUAL(1, Bit(1).get());
	ASSERT_EQUAL(0, Bit(0).get());
}

void BitTest::set()
{
	Bit b = Bit(1);
	b.set(0);
	ASSERT_EQUAL(0, b.get());
	ASSERT_EQUAL(false, b.get());
	b.set(1);
	ASSERT_EQUAL(1, b.get());
	ASSERT_EQUAL(true, b.get());
}

void BitTest::toByteArray()
{
	vector<bool> myBits; // 10011111b = 159d
	myBits.push_back(true);
	myBits.push_back(false);
	myBits.push_back(false);
	myBits.push_back(true);
	myBits.push_back(true);
	myBits.push_back(true);
	myBits.push_back(true);
	myBits.push_back(true);
	char * bytes = Bit::toByteArray(myBits);
	ASSERT_EQUAL(159, (int)(unsigned char)bytes[0]);
	myBits.push_back(false);
	myBits.push_back(true);
	myBits.push_back(true);
	myBits.push_back(false);
	myBits.push_back(false);
	myBits.push_back(true);
	myBits.push_back(false);
	myBits.push_back(true);
	delete bytes;
	bytes = Bit::toByteArray(myBits);
	ASSERT_EQUAL(159, (int)(unsigned char)bytes[0]);
	ASSERT_EQUAL(101, (int)(unsigned char)bytes[1]);
	myBits.pop_back();
	delete bytes;
	bytes = Bit::toByteArray(myBits);
	ASSERT_EQUAL(159, (int)(unsigned char)bytes[0]);
	ASSERT_EQUAL(100, (int)(unsigned char)bytes[1]);
}

void BitTest::runSuite()
{
	cute::suite s;
	s.push_back(CUTE(BitTest::get));
	s.push_back(CUTE(BitTest::set));
	s.push_back(CUTE(BitTest::toByteArray));
	cute::ide_listener lis;
	cute::makeRunner(lis)(s, "The BitTest Suite");
}

